import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Villain here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Villain extends Actor
{
      //Actor actor;
    int direccion;
    /**
     * Act - do whatever the Villain wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Villain()
    {
        direccion = Greenfoot.getRandomNumber(4);
    }
    public void act() 
    {     
        mueve();
        boolean band = this.detecta_Limite();
        //System.out.println("BORDE MUNDO   "+band);
    } 
    
   public void animaniacs()
   {
       
   }
   
   public void mueve()
   {
       Actor actor, actor2;
       
       switch(direccion)
       {
           case 0 :///DIRECCION IZQUIERDA
                actor = new Hero();
                actor2 = new Hero();
               // System.out.println(actor);
                actor = this.getOneObjectAtOffset(-3, 0, WallH.class);
                actor2 = this.getOneObjectAtOffset(-3,0, WallV.class);
                if(actor == null && actor2 == null)
                {
                    this.setLocation(this.getX()-1,this.getY());
                }
                else
                {
                    direccion =Greenfoot.getRandomNumber(4);
                }
           break;
           case 1 ://DIRECCION ARRIBA
                actor = new Hero();
                actor2 = new Hero();
                actor = this.getOneObjectAtOffset(0, -3, WallH.class);
                actor2 = this.getOneObjectAtOffset(0, -3, WallV.class);
                if(actor == null && actor2 == null)
                {
                    this.setLocation(this.getX(), this.getY()-1);
                }
                else
                {
                    direccion =Greenfoot.getRandomNumber(4);
                }
           break;
           case 2 ://DIRECCION DERECHA
                actor = new Hero();
                actor2 = new Hero();
                //System.out.println(actor);
                actor = this.getOneObjectAtOffset(2, 0, WallH.class);//VA HACIA LA DERECHA 
                actor2 = this.getOneObjectAtOffset(2 ,0, WallV.class);
                if(actor == null && actor2 == null)
                {
                    this.setLocation(this.getX() + 1, this.getY());
                }
                else
                {
                     direccion =Greenfoot.getRandomNumber(4);
                }    
           break;
           case 3 ://DIRECCION ABAJO
                actor = new Hero();
                actor2 = new Hero();
                //System.out.println(actor);
                actor = this.getOneObjectAtOffset(0, 2 ,WallH.class);
                actor2 = this.getOneObjectAtOffset(0, 2, WallV.class);
                if(actor == null && actor2 == null)
                {
                    this.setLocation(this.getX(),this.getY() + 1);
                }
                else
                {
                     direccion =Greenfoot.getRandomNumber(4);
                }
           break;
        }
   }
   
   public boolean detecta_Limite()
   {
//         Labyrinth1 miMundo;
        boolean band = false;
        Labyrinth1 mundo_Aux;
//         GreenfootImage miImagen = this.getImage();
        GreenfootImage pic = this.getImage();
//         miMundo = (Labyrinth1)getWorld();
        mundo_Aux = (Labyrinth1)getWorld();
        if(  
                ( (this.getY()-(pic.getHeight()/2)) < pic.getHeight() / 2 ) 
          )
        {
            band = true;
        }
        return band;
   }
}
